﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.components.computerdisplay {
    import reprise.ui.*;
    import flash.events.*;
    import reprise.events.*;
    import reprise.controls.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.views.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;

    public class ComputerDisplay extends UIComponent {

        private var _currentPage:PageDisplay;
        private var _pageDisplay:UIComponent;
        private var _contentDisplay:UIComponent;
        private var _numberOfPetBoxes:int;// = 0
        private var _scrollIndex:int;// = 0
        private var _morePetsAreAllowed:Boolean;
        private var _background:UIComponent;
        private var _isOpen:Boolean;// = false

        public function isOpen():Boolean{
            return (this._isOpen);
        }
        public function setHeadlineLabel(_arg1:String):void{
            Label(getElementsByClassName("headline")[0]).setLabel(_arg1);
        }
        override public function show(... _args):void{
            this._contentDisplay.addEventListener(TransitionEvent.ALL_TRANSITIONS_COMPLETE, this.show_complete);
            this._contentDisplay.addCSSClass("show");
            this.updateScrollButtonStates();
            this.setPagerButtonSelected();
            this.startPetAnimationsOnCurrentShownPage();
        }
        override protected function show_complete(_arg1:Event=null):void{
            this._contentDisplay.removeEventListener(TransitionEvent.ALL_TRANSITIONS_COMPLETE, this.show_complete);
            this._isOpen = true;
            dispatchEvent(new DisplayEvent(DisplayEvent.SHOW_COMPLETE));
        }
        override public function hide(... _args):void{
            ((this._contentDisplay.hasEventListener(TransitionEvent.ALL_TRANSITIONS_COMPLETE)) && (this._contentDisplay.removeEventListener(TransitionEvent.ALL_TRANSITIONS_COMPLETE, this.show_complete)));
            this.reset();
            this._contentDisplay.removeCSSClass("show");
            dispatchEvent(new DisplayEvent(DisplayEvent.HIDE_COMPLETE));
        }
        private function reset():void{
            var _local2:UIComponent;
            var _local3:Array;
            var _local4:RadioButton;
            var _local5:UIComponent;
            this._isOpen = false;
            var _local1:Array = getElementsByClassName("page");
            for each (_local2 in _local1) {
                _local2.remove();
                _local2 = null;
                this._currentPage = null;
            };
            this._numberOfPetBoxes = 0;
            _local3 = getElementsByClassName("pagerButton");
            for each (_local4 in _local3) {
                _local4.remove();
                _local4 = null;
            };
            _local5 = getElementsByClassName("treatPetsLayer")[0];
            if (((!(this._morePetsAreAllowed)) && (_local5))){
                _local5.remove();
                _local5 = null;
            };
        }
        public function createPetBox(_arg1:PetBoxDisplayData, _arg2:Boolean):PetBox{
            var _local4:int;
            var _local3:PetBox = new PetBox(_arg1);
            _local3.showGemReward = _arg2;
            this._numberOfPetBoxes++;
            if (((!(this._currentPage)) || (this._currentPage.isFull()))){
                _local4 = (this._currentPage) ? (this._currentPage.pageIndex + 1) : 0;
                this._currentPage = new PageDisplay(_local4, 6);
                this.addPagerButton();
                this.updatePageContainerWidth();
                this._pageDisplay.addChild(this._currentPage);
            };
            this._currentPage.addItem(_local3);
            return (_local3);
        }
        public function createTreatSomePetsFirstLayer(_arg1:String, _arg2:String):void{
            var _local3:UIComponent = this._background.addComponent("treatPetsLayer");
            RepriseUtils.addLabel(_local3, "myriadProFont treatPetsLabel", _arg1);
            RepriseUtils.addLabelButton(_local3, "myriadProFont okButton", _arg2, this.okButton_click);
        }
        private function okButton_click(_arg1:MouseEvent):void{
            this.hide();
            dispatchEvent(new Event(GameConstants.TRACK_OK_BUTTON));
        }
        private function updatePageContainerWidth():void{
            var _local1 = 518;
            var _local2 = 10;
            var _local3:Number = ((_local1 + _local2) * this._numberOfPetBoxes);
            this._pageDisplay.width = _local3;
        }
        private function addPagerButton():void{
            var _local1:UIComponent = getElementsByClassName("pagerDisplay")[0];
            var _local2:RadioButton = RepriseUtils.addRadioButton(_local1, "pagerButton", "pagerGroup");
            _local2.addEventListener(MouseEvent.CLICK, this.pageButton_click);
            var _local3:RadioButtonGroup = _local2.group();
            if (!_local3.hasEventListener(Event.CHANGE)){
                _local3.addEventListener(Event.CHANGE, this.pagerRadioButtonGroup_change);
            };
            var _local4:int = _local1.getElementsByClassName("pagerButton").length;
            var _local5 = 12;
            var _local6 = 2;
            _local1.setStyle("width", String(((_local5 + _local6) * _local4)));
            _local2.setData(this._currentPage.pageIndex);
        }
        private function pageButton_click(_arg1:MouseEvent):void{
            dispatchEvent(new InfoEvent(EventConstants.DO_TRACKING, GameConstants.TRACK_PAGER_BUTTON));
        }
        private function pagerRadioButtonGroup_change(_arg1:Event):void{
            var _local2:RadioButtonGroup = RadioButtonGroup(_arg1.target);
            this._scrollIndex = _local2.selectedData();
            this.scrollToIndex();
        }
        override protected function initialize():void{
            cssID = "computerDisplay";
            super.initialize();
        }
        override protected function createChildren():void{
            this._contentDisplay = addComponent("contentDisplay");
            this._background = this._contentDisplay.addComponent("background");
            RepriseUtils.addLabel(this._background, "showcardGothicFont headline");
            RepriseUtils.addSimpleButton(this._background, "arrowButton leftArrowButton", this.leftArrowButton_click);
            RepriseUtils.addSimpleButton(this._background, "arrowButton rightArrowButton", this.rightArrowButton_click);
            RepriseUtils.addSimpleButton(this._background, "closeButton", this.closeArrowButton_click);
            var _local1:UIComponent = this._background.addComponent("pageDisplayMask");
            this._pageDisplay = _local1.addComponent("pageDisplay");
            var _local2:UIComponent = this._background.addComponent("pagerCenterContainer");
            _local2.addComponent("pagerDisplay");
        }
        private function closeArrowButton_click(_arg1:MouseEvent):void{
            this.hide();
            dispatchEvent(new InfoEvent(EventConstants.DO_TRACKING, GameConstants.TRACK_CLOSE_BUTTON));
        }
        private function rightArrowButton_click(_arg1:MouseEvent):void{
            if (this.canScrollLeft()){
                this._scrollIndex++;
                this.scrollToIndex();
                this.setPagerButtonSelected();
            };
            dispatchEvent(new InfoEvent(EventConstants.DO_TRACKING, GameConstants.TRACK_NEXT_BUTTON));
        }
        private function leftArrowButton_click(_arg1:MouseEvent):void{
            if (this.canScrollRight()){
                this._scrollIndex--;
                this.scrollToIndex();
                this.setPagerButtonSelected();
            };
            dispatchEvent(new InfoEvent(EventConstants.DO_TRACKING, GameConstants.TRACK_PREVIOUS_BUTTON));
        }
        private function setPagerButtonSelected():void{
            var _local1:RadioButton = getElementsByClassName("pagerButton")[0];
            var _local2:RadioButtonGroup = _local1.group();
            _local2.selectRadioButtonWithData(this._scrollIndex);
        }
        private function updateScrollButtonStates():void{
            var _local2:SimpleButton;
            var _local1:SimpleButton = SimpleButton(getElementsByClassName("leftArrowButton")[0]);
            _local2 = SimpleButton(getElementsByClassName("rightArrowButton")[0]);
            _local1.enabled = this.canScrollRight();
            _local2.enabled = this.canScrollLeft();
            _local1.setVisibility(this._morePetsAreAllowed);
            _local2.setVisibility(this._morePetsAreAllowed);
        }
        private function canScrollLeft():Boolean{
            var _local1:Number = this._pageDisplay.getElementsByClassName("page").length;
            return ((((this._scrollIndex < (_local1 - 1))) && (!(this._pageDisplay.hasActiveTransitions()))));
        }
        private function canScrollRight():Boolean{
            return ((((this._scrollIndex > 0)) && (!(this._pageDisplay.hasActiveTransitions()))));
        }
        private function scrollToIndex():void{
            var _local1:UIComponent;
            _local1 = getElementsByClassName("page")[0];
            var _local2:Number = _local1.width;
            var _local3:Number = (-(this._scrollIndex) * _local2);
            this.stopAllAnimations();
            this._pageDisplay.addEventListener(TransitionEvent.ALL_TRANSITIONS_COMPLETE, this.pageDisplay_allTransitionsComplete);
            this._pageDisplay.setStyle("left", String(_local3));
            this.updateScrollButtonStates();
        }
        private function pageDisplay_allTransitionsComplete(_arg1:TransitionEvent):void{
            this._pageDisplay.removeEventListener(TransitionEvent.ALL_TRANSITIONS_COMPLETE, this.pageDisplay_allTransitionsComplete);
            this.startPetAnimationsOnCurrentShownPage();
        }
        private function startPetAnimationsOnCurrentShownPage():void{
            var _local3:PetBox;
            var _local1:PageDisplay = this._pageDisplay.getElementsByClassName("page")[this._scrollIndex];
            var _local2:Array = _local1.getElementsByClassName("petBox");
            for each (_local3 in _local2) {
                _local3.playAnimations();
            };
        }
        private function stopAllAnimations():void{
            var _local2:PetBox;
            var _local1:Array = this._pageDisplay.getElementsByClassName("petBox");
            for each (_local2 in _local1) {
                _local2.stopAnimations();
            };
        }
        public function set morePetsAreAllowed(_arg1:Boolean):void{
            this._morePetsAreAllowed = _arg1;
        }

    }
}//package net.wooga.pets.views.components.computerdisplay 
